//
//  XYViewController.m
//  Quiz
//
//  Created by Xia Yong on 12-12-4.
//  Copyright (c) 2012年 Xia Yong. All rights reserved.
//

#import "XYViewController.h"

@interface XYViewController ()
@property (strong, nonatomic) NSMutableArray *questions;
@property (strong, nonatomic) NSMutableArray *answers;
@property (readonly, nonatomic) int currentIndex;
@end

@implementation XYViewController

@synthesize questionField = _questionField;
@synthesize answerField = _answerField;

@synthesize questions = _questions;
@synthesize answers = _answers;

- (NSMutableArray *) questions {
    if(!_questions) {
        _questions = [NSMutableArray arrayWithCapacity:3];
        [_questions addObject:@"What is the 7 + 7?"];
        [_questions addObject:@"What is the capital of Vermont?"];
        [_questions addObject:@"From waht is cognac made?"];
    }
    return _questions;
}

- (NSMutableArray *) answers {
    if (!_answers) {
        _answers = [NSMutableArray arrayWithCapacity:3];
        [_answers addObject:@"14"];
        [_answers addObject:@"Monteplier"];
        [_answers addObject:@"Grapes"];
    }
    return _answers;
}


- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)showQuestion:(UIButton *)sender {
    ++_currentIndex;
    if (self.currentIndex == [self.questions count]) {
        _currentIndex = 0;
    }
    NSString *question = [self.questions objectAtIndex:self.currentIndex];
    NSLog(@"displaying the question %d: %@", self.currentIndex, question);
    self.questionField.text = question;
    //[self.questionField setText:question];
}

- (IBAction)showAnswer:(UIButton *)sender {
    NSString *answer = [self.answers objectAtIndex:self.currentIndex];
    NSLog(@"displaying the answer %d: %@", self.currentIndex, answer);
    self.answerField.text = answer;
    //[self.answerField setText:answer];
}
@end
